package com.lastcrdg.testdagger;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.lastcrdg.testdagger.base.MyApp;

import javax.inject.Inject;

public class MainActivity extends AppCompatActivity {

    @Inject
    Cloth cloth;
    @Inject
    ClothHandler clothHandler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MainComponent build = DaggerMainComponent.builder()
                        .baseComponent(((MyApp)getApplication()).getBaseComponent())
                        .mainModule(new MainModule())
                        .build();
        build.inject(this);
        TextView tv = (TextView) findViewById(R.id.tv);
        tv.setText(clothHandler.handler(cloth) + ",地址：" + clothHandler);
        Button btn = (Button) findViewById(R.id.button);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, SecondActivity.class);
                startActivity(intent);
            }
        });
    }
}
